/*
 *  Copyright (C) 2011 Glenn Rune Strandbråten
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package myrmidia.UI;

import javax.swing.JFrame;
import myrmidia.Explanation.ExplanationEngine;

/**
 * Modal user interface used to display an explanation (or any kind of text
 * output)
 * @author Glenn Rune Strandbråten
 * @version 1.0
 */
public class ExplanationUI extends javax.swing.JDialog {

    /**
     * This mode indicats that a transparency explanation should be displayed
     */
    public static final int MODE_TRANSPARENCY = 100;
    /**
     * This mode indicates that a justification explanation should be displayed
     */
    public static final int MODE_JUSTIFICATION = 200;
    /** Creates new form ExplanationUI */
    public ExplanationUI() {
        initComponents();
        getRootPane().setDefaultButton(closeButton);
    }

    /**
     * Creates new form ExplanationUI
     * @param index The index of the explanation to display
     * @param mode The mode of the explanation UI, use MODE_TRANSPARENCY or
     * MODE_JUSTIFICATION
     * @param parent The JFrame parent
     */
    public ExplanationUI(JFrame parent, int index, int mode) {
        super(parent, true);
        initComponents();
        getRootPane().setDefaultButton(closeButton);
        setLocationRelativeTo(parent);
        ExplanationEngine explEng = ExplanationEngine.getInstance();
        String expl;
        if(mode==MODE_JUSTIFICATION)
            expl = explEng.generateJustificationExplanation(index);
        else if(mode==MODE_TRANSPARENCY)
            expl = explEng.generateTransparencyExplanation(index);
        else
            expl = "No explanation were found!";
        explanationText.setText(expl);
        explanationText.setCaretPosition(0);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        closeButton = new javax.swing.JButton();
        explanationScroll = new javax.swing.JScrollPane();
        explanationText = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Myrmidia - Explanation");

        closeButton.setMnemonic('C');
        closeButton.setText("Close");
        closeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                closeButtonActionPerformed(evt);
            }
        });

        explanationText.setColumns(20);
        explanationText.setEditable(false);
        explanationText.setFont(new java.awt.Font("Tahoma", 0, 14));
        explanationText.setRows(5);
        explanationScroll.setViewportView(explanationText);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(explanationScroll, javax.swing.GroupLayout.DEFAULT_SIZE, 530, Short.MAX_VALUE))
                    .addComponent(closeButton))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(closeButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(explanationScroll, javax.swing.GroupLayout.DEFAULT_SIZE, 304, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * Action performed when the closeButton is selected
     * @param evt The ActionEvent trigger
     */
    private void closeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeButtonActionPerformed
        dispose();
    }//GEN-LAST:event_closeButtonActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ExplanationUI(null,0,0).setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton closeButton;
    private javax.swing.JScrollPane explanationScroll;
    private javax.swing.JTextArea explanationText;
    // End of variables declaration//GEN-END:variables
}
